home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / prgtools / mint / gcc / gcc261c.zoo / objects / objc-gnu2next.h < prev    next >
Encoding:
C/C++ Source or Header  |  1994-11-19  |  6.3 KB  |  236 lines

  1. /* Definitions to allow compilation of GNU objc code with NeXT runtime
  2.    Copyright (C) 1993,1994 Free Software Foundation, Inc.
  3.  
  4.    Written by:  R. Andrew McCallum <mccallum@gnu.ai.mit.edu>
  5.    Date: May 1993
  6.  
  7.    This file is part of the GNU Objective C Class Library.
  8.  
  9.    This library is free software; you can redistribute it and/or
  10.    modify it under the terms of the GNU Library General Public
  11.    License as published by the Free Software Foundation; either
  12.    version 2 of the License, or (at your option) any later version.
  13.    
  14.    This library is distributed in the hope that it will be useful,
  15.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  16.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  17.    Library General Public License for more details.
  18.  
  19.    You should have received a copy of the GNU Library General Public
  20.    License along with this library; if not, write to the Free
  21.    Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  22. */ 
  23.  
  24. /* This file is by no means complete. */
  25.  
  26. #ifndef __objc_gnu2next_h_INCLUDE_GNU
  27. #define __objc_gnu2next_h_INCLUDE_GNU
  28.  
  29. #include <objects/stdobjects.h>
  30.  
  31. #if NeXT_runtime
  32.  
  33. #define arglist_t marg_list
  34. #define retval_t void*
  35. #define TypedStream NXTypedStream
  36.  
  37. #define objc_write_type(STREAM, TYPE, VAR) \
  38.      NXWriteType(STREAM, TYPE, VAR)
  39. #define objc_write_types(STREAM, TYPE, args...) \
  40.      NXWriteTypes(STREAM, TYPE, args)
  41. #define objc_write_object(STREAM, VAR) \
  42.      NXWriteObject(STREAM, VAR)
  43. #define objc_write_object_reference(STREAM, VAR) \
  44.      NXWriteObjectReference(STREAM, VAR)
  45. #define objc_read_type(STREAM, TYPE, VAR) \
  46.      NXReadType(STREAM, TYPE, VAR)
  47. #define objc_read_types(STREAM, TYPE, args...) \
  48.      NXReadTypes(STREAM, TYPE, args)
  49. #define objc_read_object(STREAM, VAR) \
  50.      do { (*(VAR)) = NXReadObject(STREAM); } while (0)
  51. #define objc_write_root_object \
  52.      NXWriteRootObject
  53. #define objc_open_typed_stream_for_file \
  54.     NXOpenTypedStreamForFile
  55. #define objc_close_typed_stream NXCloseTypedStream
  56.  
  57. #define class_create_instance(CLASS) class_createInstance(CLASS, 0)
  58. #define sel_get_name(ASEL) sel_getName(ASEL)
  59. #define sel_get_uid(METHODNAME) set_getUid(METHODNAME)
  60. #define class_get_instance_method(CLASSPOINTER, SEL) \
  61.      class_getInstanceMethod(CLASSPOINTER, SEL)
  62. #define class_get_class_method(CLASSPOINTER, SEL) \
  63.      class_getClassMethod(CLASSPOINTER, SEL)
  64. #define class_get_class_name(CLASSPOINTER) \
  65.      (((struct objc_class*)(CLASSPOINTER))->name)
  66. #define method_get_sizeof_arguments(METHOD) \
  67.      method_getSizeOfArguments(METHOD)
  68. #define objc_lookup_class(CLASSNAME) \
  69.      objc_lookUpClass(CLASSNAME)
  70. #define sel_get_any_uid(SELNAME) \
  71.      sel_getUid(SELNAME)
  72. #define object_get_class(OBJECT) \
  73.     (((struct objc_class*)(OBJECT))->isa)
  74. #define class_get_super_class(CLASSPOINTER) \
  75.     (((struct objc_class*)(CLASSPOINTER))->super_class)
  76. #define objc_get_class(CLASSNAME) \
  77.     objc_lookUpClass(CLASSNAME)    /* not exactly right */
  78. #define class_get_version(CLASSPOINTER) \
  79.     (((struct objc_class*)(CLASSPOINTER))->version)
  80. #define __objc_responds_to(OBJECT,SEL) \
  81.     class_getInstanceMethod(object_get_class(OBJECT), SEL)
  82. #define CLS_ISMETA(CLASSPOINTER) \
  83.     ((((struct objc_class*)(CLASSPOINTER))->info) & CLS_META)
  84. #define objc_msg_lookup(OBJ,SEL) \
  85.     (class_getInstanceMethod(object_get_class(OBJ), SEL)->method_imp)
  86.  
  87. #if 1
  88. volatile void objc_fatal(const char* msg);
  89. #else
  90. #define objc_fatal(FMT, args...) \
  91.  do { fprintf (stderr, (FMT), ##args); abort(); } while (0)
  92. #endif
  93.  
  94. #define OBJC_READONLY 1
  95. #define OBJC_WRITEONLY 2
  96.  
  97.  
  98. /* Methods defined by the GNU runtime, which libobjects will provide
  99.    if the GNU runtime isn't being used. */
  100.  
  101. int objc_sizeof_type(const char* type);
  102. int objc_alignof_type(const char* type);
  103. int objc_aligned_size (const char* type);
  104. int objc_promoted_size (const char* type);
  105. inline const char* objc_skip_type_qualifiers (const char* type);
  106. const char* objc_skip_typespec (const char* type);
  107. inline const char* objc_skip_offset (const char* type);
  108. const char* objc_skip_argspec (const char* type);
  109. unsigned objc_get_type_qualifiers (const char* type);
  110.  
  111. /* The following from GNU's objc/list.h */
  112.  
  113. #include <stdio.h>
  114. #include <objects/objc-malloc.h>
  115.  
  116. struct objc_list {
  117.   void *head;
  118.   struct objc_list *tail;
  119. };
  120.  
  121. /* Return a cons cell produced from (head . tail) */
  122.  
  123. static inline struct objc_list* 
  124. list_cons(void* head, struct objc_list* tail)
  125. {
  126.   struct objc_list* cell;
  127.  
  128.   cell = (struct objc_list*)(*objc_malloc)(sizeof(struct objc_list));
  129.   cell->head = head;
  130.   cell->tail = tail;
  131.   return cell;
  132. }
  133.  
  134. /* Return the length of a list, list_length(NULL) returns zero */
  135.  
  136. static inline int
  137. list_length(struct objc_list* list)
  138. {
  139.   int i = 0;
  140.   while(list)
  141.     {
  142.       i += 1;
  143.       list = list->tail;
  144.     }
  145.   return i;
  146. }
  147.  
  148. /* Return the Nth element of LIST, where N count from zero.  If N 
  149.    larger than the list length, NULL is returned  */
  150.  
  151. static inline void*
  152. list_nth(int index, struct objc_list* list)
  153. {
  154.   while(index-- != 0)
  155.     {
  156.       if(list->tail)
  157.     list = list->tail;
  158.       else
  159.     return 0;
  160.     }
  161.   return list->head;
  162. }
  163.  
  164. /* Remove the element at the head by replacing it by its successor */
  165.  
  166. static inline void
  167. list_remove_head(struct objc_list** list)
  168. {
  169.   if ((*list)->tail)
  170.     {
  171.       struct objc_list* tail = (*list)->tail; /* fetch next */
  172.       *(*list) = *tail;/* copy next to list head */
  173.       (*objc_free)(tail);/* free next */
  174.     }
  175.   else/* only one element in list */
  176.     {
  177.       (*objc_free)(*list);
  178.       (*list) = 0;
  179.     }
  180. }
  181.  
  182.  
  183. /* Remove the element with `car' set to ELEMENT */
  184.  
  185. static inline void
  186. list_remove_elem(struct objc_list** list, void* elem)
  187. {
  188.   while (*list) {
  189.     if ((*list)->head == elem)
  190.       list_remove_head(list);
  191.     list = &((*list)->tail);
  192.   }
  193. }
  194.  
  195. /* Map FUNCTION over all elements in LIST */
  196.  
  197. static inline void
  198. list_mapcar(struct objc_list* list, void(*function)(void*))
  199. {
  200.   while(list)
  201.     {
  202.       (*function)(list->head);
  203.       list = list->tail;
  204.     }
  205. }
  206.  
  207. /* Return element that has ELEM as car */
  208.  
  209. static inline struct objc_list**
  210. list_find(struct objc_list** list, void* elem)
  211. {
  212.   while(*list)
  213.     {
  214.     if ((*list)->head == elem)
  215.       return list;
  216.     list = &((*list)->tail);
  217.   }
  218.   return NULL;
  219. }
  220.  
  221. /* Free list (backwards recursive) */
  222.  
  223. static void
  224. list_free(struct objc_list* list)
  225. {
  226.   if(list)
  227.     {
  228.       list_free(list->tail);
  229.       (*objc_free)(list);
  230.     }
  231. }
  232.  
  233. #endif /* NeXT_runtime */
  234.  
  235. #endif /* __objc_gnu2next_h_INCLUDE_GNU */
  236.